#!/bin/bash

###########################################
#安装 jsoncpp-0.6.0
###########################################

#安装python2
###########################################
#1.安装基础依赖
yum groupinstall -y "Development Tools"
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel wget
#2.下载并解压源码
cd /home
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
tar -xzf Python-2.7.18.tgz
cd Python-2.7.18
#3.配置编译选项
./configure --prefix=/usr/local/python2.7 \
            --host=aarch64-linux-gnu \
            --build=aarch64-linux-gnu \
            --enable-optimizations \
            --with-ensurepip=install
#4.编译安装
make -j 
make altinstall
#5.创建软链接，方便全局调用
sudo ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python2
sudo ln -s /usr/local/python2.7/bin/pip2.7 /usr/bin/pip2
#6.验证安装
python2 --version
pip2 --version

#安装scons
pip2 install scons
#验证安装
python2 /usr/local/python2.7/bin/scons --version

#安装
###########################################
#2.下载并解压源码
cd /home
wget https://github.com/open-source-parsers/jsoncpp/archive/refs/tags/svn-release-0.6.0-rc2.tar.gz
tar -zxf svn-release-0.6.0-rc2.tar.gz
cd jsoncpp-svn-release-0.6.0-rc2
#编译构建
python2 /usr/local/python2.7/bin/scons platform=linux-gcc
#手动安装
# 创建安装目录（如果不存在）
mkdir -p /usr/local/include/jsoncpp
mkdir -p /usr/local/lib
# 复制头文件
sudo cp -r include/json/* /usr/local/include/jsoncpp/
# 复制静态库
sudo cp libs/linux-gcc-10.3.1/libjson_linux-gcc-10.3.1_libmt.a /usr/local/lib/libjsoncpp.a
# 复制动态库
sudo cp libs/linux-gcc-10.3.1/libjson_linux-gcc-10.3.1_libmt.so* /usr/local/lib/
# 更新动态链接库缓存
sudo ldconfig
#创建软连接，将头文件放到默认搜索路径
sudo ln -s /usr/local/include/jsoncpp /usr/include/json

#############################################
#运行验证
#############################################
#创建软连接，将头文件放到默认搜索路径
sudo ln -s /usr/local/include/jsoncpp /usr/include/json
vim test_jsoncpp.cpp

#include <iostream>
#include <json/json.h>

int main() {
    Json::Value root;
    root["name"] = "John";
    root["age"] = 30;
    std::cout << root.toStyledString() << std::endl;
    return 0;
}


#编译并运行：
g++ test_jsoncpp.cpp -o test_jsoncpp -ljson_linux-gcc-10.3.1_libmt
./test_jsoncpp






